package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.interfaces.SetmealService;
import cn.itcast.pojo.Result;
import cn.itcast.pojo.Setmeal;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: peterChen
 * @date: 2019/8/14 16:26
 * @description: TODO
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;


    /**
     * 获取所有套餐
     * @return
     */
    @RequestMapping("/getSetmeal")
    public Result getSetmeal(){
        try {
            List<Setmeal> setmealList =  setmealService.getSetmeal();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
        } catch (Exception e) {
            //e.printStackTrace();
            log.error("get setmealList error.",e);
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    /**
     * 根据id获取对应套餐
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            //e.printStackTrace();
            log.error("query setmeal error.",e);
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }


}
